package com.eg366.selfFrame.service;

import java.math.BigDecimal;
import java.util.UUID;

import com.eg366.selfFrame.annotation.Bean;
import com.eg366.selfFrame.annotation.DoAfter;
import com.eg366.selfFrame.annotation.DoBefore;
import com.eg366.selfFrame.annotation.DoWired;
import com.eg366.selfFrame.dao.PayDAO;
import com.eg366.selfFrame.domain.Account;
import com.eg366.selfFrame.domain.Pay;

@Bean(id = "tranService", doAop = true, useCglib = true)
public class TranService implements ITranService {
	@DoWired
	private PayDAO payDAO;
	@DoWired
	private AccountService accountService;

	@DoBefore(aspectId = { "logAdvisor" })
	@DoAfter(aspectId = { "logAdvisor" })
	@Override
	public void doChargeTran(BigDecimal tranAmt, String vcardNo) {
		Pay pay = new Pay();
		pay.setOrderId(UUID.randomUUID().toString());
		pay.setTranCode("4006");
		pay.setTranAmt(tranAmt);
		pay.setTxnStaCd("0");
		this.payDAO.save(pay);
		Account account = accountService.getByVcardNo(vcardNo);
		account.setVcardNo(vcardNo);
		account.setCurBal(account.getCurBal().add(tranAmt));
		this.accountService.update(account);
		pay.setTxnStaCd("2");
		this.payDAO.update(pay);
	}
}